Repository navigation
feat(importers): import Hyperliquid trade history exports - #55
Merged
Merged
Conversation
Hyperliquid's trade history CSV (time, coin, dir, px, sz, ntl, fee,
closedPnl) was not detected, and mapping its columns by hand rejected
every row: its "11/8/2025 - 19:31:18" timestamps did not parse,
"(Price Improved)" directions did not match the Open/Close labels, and
the hedged Open/Close path refuses identical fills and closes whose
opening is outside the file.
- Detect the export by its headers and read it as perpetual fills.
Hyperliquid perps are one-way, so each direction (including flips such
as "Long > Short" and annotated labels) is a buy or a sell, and the
fills net exactly like broker sync's. Unknown directions and
unreadable perpetual rows stop the import; spot Buy/Sell rows are
skipped and counted because the export omits their fee token.
- Store HIP-3 markets under the API name broker sync uses ("ANTH (io)"
becomes "io:ANTH") and keep symbol case (kPEPE).
- Number identical fills, as the NinjaTrader importer does, so the same
or a later export imports once. Fills carry no import group, so they
net with synced fills of the same coin.
- Accept "M/D/YYYY - HH:MM:SS" timestamps in the shared date parser.
- Importing into a synced account adds only fills older than its first
synced fill. The export rounds times to the second, so its fills can't
share content hashes with synced fills; sync owns everything from its
first fill onward. If none of the file's fills in the synced period
match a synced fill, the statement timezone or wallet is wrong and the
import is refused. Other brokers' sync accounts, and Hyperliquid
accounts that have not synced yet, are refused too.
The reporter's anonymized 100-row export is the fixture.
Fixes #53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an importer for Hyperliquid's trade history CSV export (#53).
Cause
The export (
time, coin, dir, px, sz, ntl, fee, closedPnl) was not detected, and mapping its columns by hand rejected all 100 rows of the sample in #53.11/8/2025 - 19:31:18did not parse,Close Long (Price Improved)did not match the Open/Close labels, and the hedged Open/Close path refuses identical fills and closes whose opening is not in the file, both of which Hyperliquid exports contain.Fix
hyperliquidformat, detected by its headers. Hyperliquid perps are one-way (one net position per coin), so every direction, including flips such asLong > Shortand annotated labels, is a buy or a sell, and the fills net exactly like broker sync's. Unknown directions and unreadable perpetual rows stop the import. SpotBuy/Sellrows are skipped and counted, because the export does not say which token paid their fee.ANTH (io)becomesio:ANTH, checked against Hyperliquid'smetaendpoint), and case is kept (kPEPE).group, so they net with synced fills of the same coin.M/D/YYYY - HH:MM:SS.reconcileHyperliquidSync, called from the import route like the XTB reconciliation). The export rounds times to the second, so its fills cannot share content hashes with synced fills, which keep milliseconds; sync owns the account's history from its first synced fill on. If none of the file's fills inside the synced period match a synced fill within a second, the statement timezone or the wallet is wrong, and the import is refused. Other brokers' sync accounts, and Hyperliquid accounts that have not synced yet, are refused too. The preview counts only the fills that will be saved.Decisions worth a look:
Test
packages/importers/tests/hyperliquid.test.tsuses the reporter's anonymized 100-row export as the fixture: all 100 fills import with the right sides, symbols, fees and statement timezones, identical fills stay separate, and a reversed export has the same identities. Synthetic cases cover flips, netting with a synced fill, spot rows, and unknown or unreadable rows.apps/web/tests/hyperliquid-import.test.tsgoes through the import route. Importing again adds nothing. In a synced account the file adds only the older fill, and the short that sync alone showed becomes the long that actually closed. A wrong timezone, another broker's account and an unsynced account are refused with nothing saved.dates.test.tscovers the new separator.The sample's prices, sizes and times are scaled, so its fills do not pair into real positions; it validates parsing, not trade history. I have not run the import in the browser.
Checks run locally
pnpm format:check,pnpm typecheck,pnpm test(67 files, 635 tests),node scripts/check-licenses.mjs,pnpm -r --filter "./packages/*" buildandpnpm buildall pass. Merged together with #54, the suite also passes (68 files, 642 tests); apart from the changelog, the two touch different files.Fixes #53